/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ronsicecream.pos.stock.item;

import com.buanalintas.bynga.Controller;
import com.buanalintas.bynga.Field;
import com.buanalintas.bynga.Page;
import com.buanalintas.bynga.formatter.DateFormatter;
import com.ronsicecream.pos.entities.PosTransactionItemStock;

/**
 *
 * @author user
 */
public class HistoryItem extends Page{
     private Field itemStockId;
    
    private Field itemStockLast;
    
    private Field itemStockValue;
    
    private Field itemStockCurrent;
    
    private Field itemStockType;
    
    private Field itemStockTimestamp;
    
    private Field itemStockRegionalId;
    
    private Field itemStockStatusId;
    
//    private Field itemStockSatuanId;
    
    private Field itemStockItemId;
    
    private Field itemStockUnitId;
    
    private Field itemStockUserId;
    
    private Field itemStockPosUnitId;
    

    public HistoryItem() {
        super();

        setTheClass(PosTransactionItemStock.class);
        
        
        
        
        itemStockId = new Field();
        itemStockId.setName("itemStockId");
        itemStockId.setCaption("id");
        //itemStockId.setInfo("item stock id");
        itemStockId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        itemStockId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockId);
        
        itemStockLast = new Field();
        itemStockLast.setName("itemStockLast");
        itemStockLast.setCaption("last");
        //itemStockLast.setInfo("item stock last");
        itemStockLast.setListProperties(" align=\"left\" width=\"5%\" nowrap");
        itemStockLast.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockLast);
        
        itemStockValue = new Field();
        itemStockValue.setName("itemStockValue");
        itemStockValue.setCaption("value");
        //itemStockValue.setInfo("item stock value");
        itemStockValue.setListProperties(" align=\"left\" width=\"5%\" nowrap");
        itemStockValue.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockValue);
        
        itemStockCurrent = new Field();
        itemStockCurrent.setName("itemStockCurrent");
        itemStockCurrent.setCaption("current");
        //itemStockCurrent.setInfo("item stock current");
        itemStockCurrent.setListProperties(" align=\"left\" width=\"5%\" nowrap");
        itemStockCurrent.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockCurrent);
        
        itemStockType = new Field();
        itemStockType.setName("itemStockType");
        itemStockType.setCaption("type");
        itemStockType.setListProperties(" align=\"left\" size=\"50\" ");
        itemStockType.setInputProperties(" ");
        itemStockType.getOptions().add(new String[]{"1", "Receipt From Supplier"});
        itemStockType.getOptions().add(new String[]{"2", "Retur To Supplier"});
        itemStockType.getOptions().add(new String[]{"3", "Distribution Warehouse To Mainkitchen"});
        itemStockType.getOptions().add(new String[]{"4", "Distribution Warehouse To Outlet"});
        itemStockType.getOptions().add(new String[]{"5", "Retur Mainkitchen to Warehouse"});
        itemStockType.getOptions().add(new String[]{"6", "Opname Item"});
        itemStockType.getOptions().add(new String[]{"7", "Input Sale"});
        itemStockType.getOptions().add(new String[]{"8", "Receipt Production"});
        itemStockType.getOptions().add(new String[]{"9", "Receipt Main Kitchen From Warehouse"});
        itemStockType.getOptions().add(new String[]{"~", "Receipt Outlet From Warehouse"});
        itemStockType.getOptions().add(new String[]{"!", "Receipt Outlet From Main Kitchen"});
        itemStockType.getOptions().add(new String[]{"@", "Retur Outlet to Main Kitchen"});
        itemStockType.getOptions().add(new String[]{"#", "Retur Outlet to Warehouse"});
        itemStockType.getOptions().add(new String[]{"$", "Distribution Mainkitchen To Outlet"});
        itemStockType.setInputType(Field.INPUT_COMBO_BOX);
        getFields().add(itemStockType);
        
        itemStockTimestamp = new Field();
        itemStockTimestamp.setName("itemStockTimestamp");
        itemStockTimestamp.setCaption("timestamp");
        //itemStockTimestamp.setInfo("item stock timestamp");
        itemStockTimestamp.setListProperties(" align=\"center\" width=\"5%\" nowrap");
        itemStockTimestamp.setInputProperties(" size=\"12\"");
//        itemStockTimestamp.setFormatter(DateFormatter.getInstanceDateTime(this));
        getFields().add(itemStockTimestamp);
        
        itemStockRegionalId = new Field();
        itemStockRegionalId.setName("itemStockRegionalId");
        itemStockRegionalId.setCaption("regional");
        //itemStockRegionalId.setInfo("item stock regional id");
        itemStockRegionalId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        itemStockRegionalId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockRegionalId);
        
        itemStockStatusId = new Field();
        itemStockStatusId.setName("itemStockStatusId");
        itemStockStatusId.setCaption("status");
        //itemStockStatusId.setInfo("item stock status id");
        itemStockStatusId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        itemStockStatusId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockStatusId);
//        
        itemStockPosUnitId = new Field();
        itemStockPosUnitId.setName("itemStockPosUnitId");
        itemStockPosUnitId.setCaption(" pos unit");
        //itemStockSatuanId.setInfo("item stock satuan id");
        itemStockPosUnitId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        itemStockPosUnitId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockPosUnitId);
        
        itemStockItemId = new Field();
        itemStockItemId.setName("itemStockItemId");
        itemStockItemId.setCaption(" item");
        //itemStockItemId.setInfo("item stock item id");
        itemStockItemId.setListProperties(" align=\"left\" width=\"15%\" nowrap");
        itemStockItemId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockItemId);
        
        itemStockUnitId = new Field();
        itemStockUnitId.setName("itemStockUnitId");
        itemStockUnitId.setCaption("unit");
        //itemStockUnitId.setInfo("item stock unit id");
        itemStockUnitId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        itemStockUnitId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockUnitId);
        
        itemStockUserId = new Field();
        itemStockUserId.setName("itemStockUserId");
        itemStockUserId.setCaption("user");
        //itemStockUserId.setInfo("item stock user id");
        itemStockUserId.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        itemStockUserId.setInputProperties(" size=\"20\"");        
        getFields().add(itemStockUserId);
        

        fillFields();
        
        getFieldsAdd().clear();
        getFieldsAdd().add(itemStockStatusId);

        getFieldsEdit().clear();
        getFieldsEdit().add(itemStockItemId);
        getFieldsEdit().add(itemStockStatusId);

        getFieldsList().clear();
        getFieldsList().add(itemStockUserId);
        getFieldsList().add(itemStockUnitId);
        getFieldsList().add(itemStockItemId);
        getFieldsList().add(itemStockRegionalId);
        getFieldsList().add(itemStockPosUnitId);
        getFieldsList().add(itemStockType);
        getFieldsList().add(itemStockLast);
        getFieldsList().add(itemStockValue);
        getFieldsList().add(itemStockCurrent);
        getFieldsList().add(itemStockTimestamp);

        getFieldsView().clear();
        getFieldsView().add(itemStockUserId);
        getFieldsView().add(itemStockUnitId);
        getFieldsView().add(itemStockItemId);
        getFieldsView().add(itemStockStatusId);
        getFieldsView().add(itemStockType);
        getFieldsView().add(itemStockLast);
        getFieldsView().add(itemStockValue);
        getFieldsView().add(itemStockCurrent);
        getFieldsView().add(itemStockTimestamp);
        
        setController(new HistoryItemController(this));
    }
    @Override
    public void beforeList() {
        if (!getCurrentUnit().getUnitId().equals(1)) {
            getController().setCondition("t.itemStockUnitId.unitId=" + getCurrentUnit().getUnitId());
        } else {
            return;
        }

    }
    
    class HistoryItemController extends Controller {

        public HistoryItemController(Page page) {
            super(page);
            setOrder(itemStockTimestamp);
            setOrderType("DESC");
        }
    }
}
